var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
const session=require("express-session");
const filestore=require("session-file-store")(session);
const sessionMiddleWare-session({
  store:new FileStore(),
  secret:"可以是任何密码",
  cookie:{maxAge:60000};
});
var bodyParser = require('body-parser');
var sassMiddleware = require('node-sass-middleware');

var index = require('./routes/index');
var users = require('./routes/users');
var r07=require('./routes/07');
var r09=require('./routes/09');
const r10=require('./routes/10');
const r11=require('./routes/11');//这个只是路由处理器的名字
const r12=require('./routes/12');
const r13=require('./routes/13');
const r14=require('./routes/15');

var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(sessionMiddleWare);
app.use(sassMiddleware({
  src: path.join(__dirname, 'public'),
  dest: path.join(__dirname, 'public'),
  indentedSyntax: true, // true = .sass and false = .scss
  sourceMap: true
}));
app.use(express.static(path.join(__dirname, 'public')));

app.use('/', index);
app.use('/users', users);
app.use('/lesson07',r07);
app.use('/lesson09',r09);
app.use('/lesson10',r10);
app.use('/lesson11',r11);//与用户发送的请求匹配时，调用这个路由处理器
app.use('/lesson12',r12);
app.use('/lesson13',r13);
// app.use('/lesson14',r14);
app.use("/lesson14",r14);
app.use("/lesson16",require("./routes/16"));
app.use("/lesson17",require("./routes/17"));
app.use("/lesson18",require("./routes/18"));
app.use("/lesson19",require("./routes/19"));


// catch 404 and forward to error handler
app.use(function(req, res, next) {
  var err = new Error('Not Found');
  err.status = 404;
  next(err);
});

// error handler
app.use(function(err, req, res, next) {
  // set locals, only providing error in development
  res.locals.message = err.message;
  res.locals.error = req.app.get('env') === 'development' ? err : {};

  // render the error page
  res.status(err.status || 500);
  res.render('error');
});

module.exports = app;
